//
//  GetUploadMsg.m
//
//  Created by 啊  on 16/5/6
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "GetUploadMsg.h"


NSString *const kGetUploadMsgName = @"name";
NSString *const kGetUploadMsgToken = @"token";
NSString *const kGetUploadMsgDomain = @"domain";


@interface GetUploadMsg ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation GetUploadMsg

@synthesize name = _name;
@synthesize token = _token;
@synthesize domain = _domain;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.name = [self objectOrNilForKey:kGetUploadMsgName fromDictionary:dict];
            self.token = [self objectOrNilForKey:kGetUploadMsgToken fromDictionary:dict];
            self.domain = [self objectOrNilForKey:kGetUploadMsgDomain fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.name forKey:kGetUploadMsgName];
    [mutableDict setValue:self.token forKey:kGetUploadMsgToken];
    [mutableDict setValue:self.domain forKey:kGetUploadMsgDomain];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.name = [aDecoder decodeObjectForKey:kGetUploadMsgName];
    self.token = [aDecoder decodeObjectForKey:kGetUploadMsgToken];
    self.domain = [aDecoder decodeObjectForKey:kGetUploadMsgDomain];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_name forKey:kGetUploadMsgName];
    [aCoder encodeObject:_token forKey:kGetUploadMsgToken];
    [aCoder encodeObject:_domain forKey:kGetUploadMsgDomain];
}

- (id)copyWithZone:(NSZone *)zone
{
    GetUploadMsg *copy = [[GetUploadMsg alloc] init];
    
    if (copy) {

        copy.name = [self.name copyWithZone:zone];
        copy.token = [self.token copyWithZone:zone];
        copy.domain = [self.domain copyWithZone:zone];
    }
    
    return copy;
}


@end
